﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GenericStyleSelector.cs" company="Marcin Jastrzebski">
//   Copyright (c) Marcin Jastrzebski (marcin@marcinj.net)
// </copyright>
// <summary>
//   The generic style selector.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace mPassRT.Selectors
{
    using System.Collections.Generic;

    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;

    /// <summary>The generic style selector.</summary>
    public class GenericStyleSelector : StyleSelector
    {
        #region Constructors and Destructors

        /// <summary>Initializes a new instance of the <see cref="GenericStyleSelector"/> class.</summary>
        public GenericStyleSelector()
        {
            this.Mappings = new List<StyleSelectorMapping>();
        }

        #endregion

        #region Public Properties

        /// <summary>Gets or sets the mappings.</summary>
        public List<StyleSelectorMapping> Mappings { get; set; }

        #endregion

        #region Methods

        /// <summary>Selects the style.</summary>
        /// <param name="item">The item.</param>
        /// <param name="container">The container.</param>
        /// <returns>The <see cref="Style"/>.</returns>
        protected override Style SelectStyleCore(object item, DependencyObject container)
        {
            if (item == null)
            {
                return base.SelectStyleCore(null, container);
            }

            var mapping = (StyleSelectorMapping)SelectorHelper.GetMapping(item, this.Mappings);
            if (mapping == null)
            {
                return base.SelectStyleCore(item, container);
            }

            return mapping.MappedStyle;
        }

        #endregion
    }
}